<?php

namespace App\Console\Commands;

use App\Services\CouponService;
use Illuminate\Console\Command;

class ExpireUserCoupons extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'coupons:expire';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '标记过期的用户优惠券';

    protected CouponService $couponService;

    /**
     * Create a new command instance.
     */
    public function __construct(CouponService $couponService)
    {
        parent::__construct();
        $this->couponService = $couponService;
    }

    /**
     * Execute the console command.
     */
    public function handle(): int
    {
        $this->info('开始处理过期的用户优惠券...');

        $expiredCount = $this->couponService->expireUserCoupons();

        if ($expiredCount > 0) {
            $this->info("成功标记 {$expiredCount} 张过期优惠券");
        } else {
            $this->info('没有发现过期的优惠券');
        }

        $this->info('优惠券过期处理完成！');

        return Command::SUCCESS;
    }
}